Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pubsub: fix permadiff with configuring an empty retry_policy. #11834

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

anavada
Copy link
Contributor

@anavada anavada commented Sep 26, 2024

Fixes hashicorp/terraform-provider-google#18016

The permadiff arises when users specify an empty retry policy as retry_policy: {} in their config, but the empty value doesn't get sent to the API and the API subsequently doesn't return a retry_policy in the response. By setting send_empty_value: true on the retry_policy property, we ensure that the API recognizes the user-configured value.

Similar fixes for other resource properties will be investigated and sent in separate PRs.

Release Note Template for Downstream PRs (will be copied)

pubsub: fix permadiff with configuring an empty `retry_policy`.

Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@melinath, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 42 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 2 files changed, 42 insertions(+), 2 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 53
Passed tests: 26
Skipped tests: 1
Affected tests: 26

Click here to see the affected service packages
  • pubsub

Action taken

Found 26 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccDataSourceGooglePubsubSubscription_basic
  • TestAccDataSourceGooglePubsubSubscription_optionalProject
  • TestAccPubsubSubscriptionBigQuery_serviceAccount
  • TestAccPubsubSubscriptionBigQuery_update
  • TestAccPubsubSubscriptionCloudStorage_serviceAccount
  • TestAccPubsubSubscriptionCloudStorage_updateAvro
  • TestAccPubsubSubscriptionCloudStorage_updateText
  • TestAccPubsubSubscriptionIamBinding
  • TestAccPubsubSubscriptionIamMember
  • TestAccPubsubSubscriptionIamPolicy
  • TestAccPubsubSubscription_emptyRetryPolicy
  • TestAccPubsubSubscription_emptyTTL
  • TestAccPubsubSubscription_filter
  • TestAccPubsubSubscription_pollOnCreate
  • TestAccPubsubSubscription_pubsubSubscriptionDeadLetterExample
  • TestAccPubsubSubscription_pubsubSubscriptionPullFilterExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushBqServiceAccountExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageAvroExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageServiceAccountExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushExample
  • TestAccPubsubSubscription_push
  • TestAccPubsubSubscription_pushNoWrapper
  • TestAccPubsubSubscription_pushNoWrapperEmpty

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccDataSourceGooglePubsubSubscription_basic[Debug log]
TestAccDataSourceGooglePubsubSubscription_optionalProject[Debug log]
TestAccPubsubSubscriptionBigQuery_serviceAccount[Debug log]
TestAccPubsubSubscriptionBigQuery_update[Debug log]
TestAccPubsubSubscriptionCloudStorage_serviceAccount[Debug log]
TestAccPubsubSubscriptionCloudStorage_updateAvro[Debug log]
TestAccPubsubSubscriptionCloudStorage_updateText[Debug log]
TestAccPubsubSubscriptionIamBinding[Debug log]
TestAccPubsubSubscriptionIamMember[Debug log]
TestAccPubsubSubscriptionIamPolicy[Debug log]
TestAccPubsubSubscription_emptyRetryPolicy[Debug log]
TestAccPubsubSubscription_emptyTTL[Debug log]
TestAccPubsubSubscription_filter[Debug log]
TestAccPubsubSubscription_pollOnCreate[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionDeadLetterExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPullFilterExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushBqServiceAccountExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageAvroExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushCloudstorageServiceAccountExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushExample[Debug log]
TestAccPubsubSubscription_push[Debug log]
TestAccPubsubSubscription_pushNoWrapper[Debug log]
TestAccPubsubSubscription_pushNoWrapperEmpty[Debug log]

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{red}{\textsf{Tests failed during RECORDING mode:}}$
TestAccPubsubSubscription_pubsubSubscriptionPushBqExample[Error message] [Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample[Error message] [Debug log]

$\textcolor{red}{\textsf{Errors occurred during RECORDING mode. Please fix them to complete your PR.}}$

View the build log or the debug log for each test

@@ -471,6 +471,7 @@ properties:
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
default_from_api: true
diff_suppress_func: 'tpgresource.DurationDiffSuppress'
send_empty_value: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want allow_empty_object here as well, though it looks like the tests are passing, so maybe it's fine? Did you happen to try that out?

Suggested change
send_empty_value: true
send_empty_value: true
allow_empty_object: true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the earlier BQ-related test failures seem unrelated and are passing now. Thanks for opening hashicorp/terraform-provider-google#19683.

Those tests pass locally as well:

$ make testacc TEST=./google-beta/services/pubsub TESTARGS='-run=TestAccPubsubSubscription_pubsubSubscriptionPushBqExample'
==> Checking that code complies with gofmt requirements...
go vet
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google-beta/services/pubsub -v -run=TestAccPubsubSubscription_pubsubSubscriptionPushBqExample -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc"
=== RUN   TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
=== PAUSE TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
=== CONT  TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
--- PASS: TestAccPubsubSubscription_pubsubSubscriptionPushBqExample (30.70s)
PASS
ok      github.com/hashicorp/terraform-provider-google-beta/google-beta/services/pubsub 31.317s

$ make testacc TEST=./google-beta/services/pubsub TESTARGS='-run=TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample'
==> Checking that code complies with gofmt requirements...
go vet
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google-beta/services/pubsub -v -run=TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google-beta/version.ProviderVersion=acc"
=== RUN   TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
=== PAUSE TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
=== CONT  TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample
--- PASS: TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample (30.34s)
PASS
ok      github.com/hashicorp/terraform-provider-google-beta/google-beta/services/pubsub 30.958s

Similarly, the "VCR-test" was flaky as well but is passing now. However, the terraform-google-conversion-build-and-unit-tests failures show a permadiff with "retryPolicy": nil, (example test case and test code throwing the error). I think that I'd need to submit a separate PR to fix those tests since they are in a different repo.

I think you'll want allow_empty_object here as well, though it looks like the tests are passing, so maybe it's fine? Did you happen to try that out?

I didn't see that in the field reference but I see it here and used elsewhere in Subscription.yaml. But yeah, the tests are passing with or without allow_empty_object and I'm not sure why, but it doesn't seem like adding allow_empty_object will hurt so I've added it.

@github-actions github-actions bot requested a review from melinath September 30, 2024 22:15
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 42 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 2 files changed, 42 insertions(+), 2 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 1 insertion(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 55
Passed tests: 52
Skipped tests: 1
Affected tests: 2

Click here to see the affected service packages
  • pubsub

Action taken

Found 2 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccPubsubSubscription_pubsubSubscriptionPushBqExample
  • TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccPubsubSubscription_pubsubSubscriptionPushBqExample[Debug log]
TestAccPubsubSubscription_pubsubSubscriptionPushBqTableSchemaExample[Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 48 insertions(+), 6 deletions(-))
google-beta provider: Diff ( 2 files changed, 48 insertions(+), 6 deletions(-))
terraform-google-conversion: Diff ( 1 file changed, 7 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 55
Passed tests: 54
Skipped tests: 1
Affected tests: 0

Click here to see the affected service packages
  • pubsub

🟢 All tests passed!

View the build log

Copy link
Member

@melinath melinath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like send_empty_value means that the nil value also needs to be included in TGC tests. Basically that means adding it to the data for both suscriptions in https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/third_party/tgc/tests/data/example_pubsub_subscription.json, and also adding it to the subscription data in the example_pubsub_subscription_iam_*.json files in the same directory.

@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 48 insertions(+), 6 deletions(-))
google-beta provider: Diff ( 2 files changed, 48 insertions(+), 6 deletions(-))
terraform-google-conversion: Diff ( 5 files changed, 15 insertions(+), 6 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 55
Passed tests: 54
Skipped tests: 1
Affected tests: 0

Click here to see the affected service packages
  • pubsub

🟢 All tests passed!

View the build log

@anavada
Copy link
Contributor Author

anavada commented Oct 3, 2024

It looks like send_empty_value means that the nil value also needs to be included in TGC tests.

Ah right, thanks. Updated and all tests are passing.

I'm not 100% clear on why we needed to change these tests but not the existing tests here however. send_empty_value is only supposed to send empty values to the API if they are explicitly set in the user config but they were not in the affected TGC tests.

Copy link
Member

@melinath melinath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% clear on why we needed to change these tests but not the existing tests here however. send_empty_value is only supposed to send empty values to the API if they are explicitly set in the user config but they were not in the affected TGC tests.

It looks like the send_empty_value docs are incorrect - the resource will also send the value if the field isn't set. This is probably why all the tests had to be re-recorded here: #11834 (comment) (because they all started sending the field as null, which didn't match the previous requests.)

As long as that's the same for the API as not sending the field, this should be fine. Let me know!

@anavada
Copy link
Contributor Author

anavada commented Oct 8, 2024

As long as that's the same for the API as not sending the field, this should be fine. Let me know!

Yeah it shouldn't be an issue for the API (as evidenced by the existing acceptance tests passing). I was just concerned about potentially breaking folks' Terraform code, but I don't think that will be a problem either.

@github-actions github-actions bot requested a review from melinath October 8, 2024 20:57
niharika-98 pushed a commit to niharika-98/magic-modules that referenced this pull request Oct 10, 2024
karolgorc pushed a commit to karolgorc/magic-modules that referenced this pull request Oct 11, 2024
akshat-jindal-nit pushed a commit to akshat-jindal-nit/magic-modules that referenced this pull request Nov 18, 2024
amanMahendroo pushed a commit to amanMahendroo/magic-modules that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google_pubsub_subscription TF changes at every plan
3 participants